﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Paint(object sender, PaintEventArgs e)
        {
            //e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Blue)), new Point(0, 0), new Point(100, 100));


            //Font font = new Font("黑体", 40);
            //SolidBrush bluepen = new SolidBrush(Color.Blue);
            //SolidBrush blackpen = new SolidBrush(Color.Black);
            //e.Graphics.DrawString("VC#", font, blackpen, 0, 0);
            //e.Graphics.DrawString("VC#", font, bluepen, 61, 21);

            //SoundPlayer player = new SoundPlayer(Properties.Resources.add);
            //player.Play();

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            //MessageBox.Show("hello world");
            //this.label1.Text = Application.StartupPath;

            //for (int i = 0; i < 10000; i++)
            //{
            //    label1.Text = i.ToString();
            //    label1.Refresh();
            //}  


            //this.StartPosition = FormStartPosition.CenterParent;
            Bitmap bitmap = new Bitmap(1000, 200, PixelFormat.Format32bppArgb);
            Graphics g = null;
            g = Graphics.FromImage(bitmap);
            Color back_ground = Color.Blue;
            g.FillRectangle(new SolidBrush(back_ground), new Rectangle(0, 0, 1500, 150));


            //MemoryStream tempStream = new MemoryStream();
            //bitmap.Save(tempStream, ImageFormat.Png);

            //string resultstring_Post = "";
            //byte[] read = new byte[5000];
            ////int bytes = tempStream.Read(read, 0, 5000);
            ////while (bytes > 0)
            ////{
            ////    resultstring_Post += System.Text.Encoding.UTF8.GetString(read, 0, bytes);
            ////    //bytes = tempStream.Read(read, 0, 5000);
            ////}
            //read = tempStream.ToArray();

            //MemoryStream tempStream1 = new MemoryStream(read, 0, 4703);


            //Bitmap b1 = new Bitmap(tempStream1);


            //this.pictureBox1.Image = b1;

            this.pictureBox1.Image = bitmap;


        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("hello world");
            ArrayList a = new ArrayList();
            string s = "";
            int m = 5;

            for (int i = 0; i < m; i++)
            {
                a.Add("*");
            }
            for (int i = 0; i < m; i++)
            {
                for (int j = m; j > i; j--)
                {
                    s += a[j - 1].ToString();

                }
                s += "\n";

            }
            this.richTextBox1.Text = s;



        }

        private void button2_Click(object sender, EventArgs e)
        {
            FlashWindow(this.Handle, false);
        }

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern bool MessageBeep(uint uType);

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBeep(1);
        }

        [DllImport("user32.dll")]
        public static extern bool FlashWindow(
            IntPtr hWnd,     // handle to window
            bool bInvert   // flash status
            );

        private void button4_Click(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            Thread nt = new Thread(new ThreadStart(this.display));
            nt.Start();




            //MyMethod m = new MyMethod(this.display);

            //this.BeginInvoke(m);

            Thread.Sleep(1000);
            display();
        }
        public delegate void MyMethod();

        void display()
        {

            //lock (this)


            for (int i = 1; i < 10; i++)
            {
                this.label1.Text += i.ToString() + ",";
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            var a = new Label();
            a.Text = "zzzz";
            this.Controls.Add(a);
        }

        private void button6_Click(object sender, EventArgs e)
        {

            MessageBox.Show("1");

            Task t1 = Task.Factory.StartNew(() => k1());

            Task t2 = Task.Factory.StartNew(() => k2());

            //Task.WaitAll(t1, t2);


            //Cursor.Current = new Cursor(this.Handle);
            //LoadCursor(@"D:\all\常用资料\code\project\old\2015-04-28 基础 类库\BaseApplication\WindowsFormsApplication1\Resources\tank.cur");
            //Cursor.Current = LoadCursor(@"D:\all\常用资料\code\project\old\2015-04-28 基础 类库\BaseApplication\WindowsFormsApplication1\Resources\tank.cur");
        }

        void k1()
        {

            for (int i = 0; i < 100; i++)
            {

                Thread.Sleep(100);

                this.Invoke(new Action(

                    () => { this.label1.Text = i.ToString(); }));

            }

        }



        void k2()
        {

            for (int i = 0; i < 100; i++)
            {

                Thread.Sleep(100);

                this.Invoke(new Action(

                    () => { this.label2.Text = i.ToString(); }));

            }

        }

        public static Cursor LoadCursor(string resourceName)
        {
            try
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    //return new Cursor(@"D:\代码查询\WindowsApplication1\bin\Debug\中间层\分类\系统\屏幕的捕捉\Screen_Capturing_src\Taking Screen Captures\Finder.cur");

                    return new Cursor(resourceName);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return null;
        }

        private void Form3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F1)
                MessageBox.Show("bangzhu");

        }

        private void Form3_KeyPress(object sender, KeyPressEventArgs e)
        {
            //if (e.KeyData == Keys.F1)
            //    MessageBox.Show("bangzhu");

        }

        private void Form3_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F1)
                MessageBox.Show("bangzhu");
        }

        private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F1)
                MessageBox.Show("bangzhu");

            Cursor.Current = LoadCursor(@"D:\all\常用资料\code\project\old\2015-04-28 基础 类库\BaseApplication\WindowsFormsApplication1\Resources\tank.cur");
        }

    }




}
